package com.xs.readword;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xs.readword.Slide.SlideActivity;

public class MainActivity extends AppCompatActivity {

    //声明控件
    private Button btn_login,btn_register;
    private EditText edit_user,edit_pwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找到控件
        btn_login = findViewById(R.id.btn_login);
        btn_register = findViewById(R.id.btn_register);
        edit_user = findViewById(R.id.edit_user);
        edit_pwd = findViewById(R.id.edit_pwd);
        //点击登录按钮
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //需要获取输入的用户名和密码
                String username = edit_user.getText().toString();
                String password = edit_pwd.getText().toString();
                //弹出内容设置
                String ok = "登录成功";
                String fail = "登录失败，账号或密码错误！";

                Intent intent = null;

                if(TextUtils.isEmpty(username)){
                    //弹出框，提示框
                    Toast.makeText(MainActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if (TextUtils.isEmpty(password)){
                    //弹出框，提示框
                    Toast.makeText(MainActivity.this, "密码不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if(username.equals("lxs")&&password.equals("123456")){
                    //Toast普通版
                    Toast.makeText(MainActivity.this, ok, Toast.LENGTH_SHORT).show();

                    //如果正确的话进行跳转
                    intent = new Intent(MainActivity.this, SlideActivity.class);
                    startActivity(intent);
                }else{
                    //不正确,弹出登录失败
                    //提升版Toast，居中
                    Toast toastCenter = Toast.makeText(getApplicationContext(), fail, Toast.LENGTH_SHORT);
                    toastCenter.setGravity(Gravity.CENTER,0,0);
                    toastCenter.show();
                }
                //假设正确的账号和密码分别是lxs，123456

            }
        });

//        Button btn_login =findViewById(R.id.btn_login);
//        btn_login.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(MainActivity.this, WordOperateActivity.class);
//                startActivity(intent);
//            }
//        });
//        Button btn_register = findViewById(R.id.btn_register);
//        btn_register.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
//                startActivity(intent);
//            }
//        });
    }
}